<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div{
            margin: 0 auto;
            border: 1px solid red;
            width: 100px;
            height: 100px;
            font-size: 50px;
            text-align: center;
            line-height: 100px;
            background-color: pink;
        }
        button{
            margin: 0 auto;
            /* background-color: #663399; */
            display: block;
            width: 50px;
            height: 50px;
        }
    </style>
</head>
<body>
    <div class="box">
        <span>10</span>
    </div>
    <button>开始</button>
    <script>

        // 2. 倒计时
            // - 三个按钮，先实现基本功能，不用控制按钮的禁用
        var button=document.getElementsByTagName('button')[0]
        var span=document.getElementsByTagName('span')[0]
        var div=document.getElementsByTagName('div')[0]

        var t
        console.log(button,span,div)
        button.onclick=function(){
            var btntext=button.innerText
            if(btntext == '开始'){
                button.innerText='暂停'
                // clearInterval(t)
                t = setInterval(() => {
                    span.innerText -= 1 
                    if(span.innerText == 0 ){
                        clearInterval(t)
                        button.innerText = '重置'
                    }
                }, 100);
            }else if(btntext == '暂停'){
                button.innerText = '继续'
                clearInterval(t)
            }else if(btntext == '继续'){
                button.innerText='暂停'
                t = setInterval(() => {
                    span.innerText -= 1 
                    if(span.innerText == 0 ){
                        clearInterval(t)
                        button.innerText = '重置'
                    }
                }, 100);
            }else if(btntext = '重置'){
                span.innerText = 10 
                button.innerText = '开始'
            }
        }

    </script>
</body>
</html>